import { defineConfig } from '@celi/admin-snippets'

const portRewriteMap = {
  9001: '/api',
  9003: '/api/xg-mes-plan',
  9004: '/api/xg-mes-production',
  9005: '/api/xg-mes-material',
  9006: '/api/xg-mes-auth',
}

export default defineConfig({
  root: `src/renderer/src`,
  lowcodeServer: 'http://192.168.50.161',
  proxy: {
    // isPass: (path) => path.includes('/auth/listPermissionByMasterKey'),
    websocket: {
      '/ws': 'ws://192.168.50.161:9406',
    },
    rewrite(path, address) {
      const { port } = new URL(address)

      return path.replace(`${portRewriteMap[port]}`, '')
    },
  },
  patchPath(path, address) {
    const { port, pathname } = new URL(address)

    return `${portRewriteMap[port]}${pathname}${path}`.replace(/\/+/g, '/')
  },
  address: [
    {
      label: '服务器',
      value: 'server',
      children: [
        { label: '生产', value: 'http://192.168.50.161:9001/xg-mes-production' },
        { label: '计划', value: 'http://192.168.50.161:9001/xg-mes-plan' },
        { label: '原料', value: 'http://192.168.50.161:9001/xg-mes-material' },
        { label: '权限', value: 'http://192.168.50.161:9001/xg-mes-auth' },
      ],
    },
    {
      label: '本地',
      value: 'local',
      children: [
        { label: '生产', value: 'http://192.168.50.175:9004' },
        { label: '计划', value: 'http://192.168.50.175:9003' },
        { label: '原料', value: 'http://192.168.50.175:9005' },
        { label: '权限', value: 'http://192.168.50.175:9006' },
      ],
    },
  ],
})
